package com.xlhj.boot.jpa.dao;

import com.xlhj.boot.jpa.entity.SysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @ClassName SysUserDao
 * @Description 用户表持久层接口
 * @Author liucaijing
 * @Date 2021/2/24 15:40
 * @Version 1.0
 */
@Repository
public interface SysUserRepository extends JpaRepository<SysUser, Long>, JpaSpecificationExecutor<SysUser> {

    @Query(value = "from sys_user user where user.userName = ?1")
    SysUser findUserByUserName(String userName);

    @Query(value = "update sys_user set userName = ?2 where id = ?1")
    @Modifying
    int updateUserById(Long id, String userName);

    @Query(value = "select * from sys_user where user_code = :userCode", nativeQuery = true)
    SysUser findUserByUserCode(String userCode);
}
